﻿<cfscript>
    view = createObject("component", "#session.rootDir#.views.layout");
    view.init("Dynamic Group Management", "/jquery/plugins/tablesorter/jquery.tablesorter.min.js, /#session.rootDir#/static/js/allgroups.js", 
        "", main);
    view.setSideBar("noSidebar");
    view.html();
</cfscript>

<cffunction name="main" access="public" output="true" returntype="any"> 
    <cfscript>
        AllGroups = createObject("component", "#session.rootDir#.objects.Groups").init();
        AjaxController = '/#session.rootDir#/controller/AjaxHandler.cfm';
        GroupQuery = new query();
        GroupQuery.setAttributes(GetAllGroups = AllGroups.getAllADGroups());
        groups = GroupQuery.execute(sql = "SELECT * FROM GetAllGroups ORDER BY sAmAccountName", dbtype="query");
        groups = groups.getResult();
        ViewUser = "/#session.rootDir#/users/viewuser.cfm?ADUser=";
        ViewGroup = "/#session.rootDir#/groups/viewgroup.cfm?ADGroup=";
    </cfscript>
    
    <!---<style>
        /*  table sorter styles  */
        ##groups th.headerSortUp { 
            background-image: url(/#session.rootDir#/images/asc.gif);
            background-repeat: no-repeat;
            background-position: center right; 
        } 
        ##groups th.header { 
            background-image: url(/#session.rootDir#/images/bg.gif);
            cursor: pointer; 
            font-weight: bold; 
            background-repeat: no-repeat;
            background-position: center right; 
        } 
        ##groups th.headerSortDown { 
            background-image: url(/#session.rootDir#/images/desc.gif); 
            background-repeat: no-repeat;
            background-position: center right;
        } 
    </style>--->
    
    <cfform name="myfrm">
        <input type="hidden" id="ViewUser" value="#ViewUser#"/ >
        <input type="hidden" id="ViewGroup" value="#ViewGroup#"/ >
        <h3>AD Groups #groups.RecordCount#</h3>
        <table class="dataTable tablesorter" id="groups">
            <thead>
                <tr>
                    <th>Group</th>
                    <th>Manger</th>
                    <th>Group Type</th>
                    <th>Members</th>
                </tr>
            </thead>
            <tbody>
                <cfloop query="groups">                
                    <tr>
                        <td><a href="#ViewGroup##trim(sAmAccountName)#">#sAmAccountName#</a></td>
                        <cfset Manager = AllGroups.SCFAD.getAccountNameByDN(managedBy) />
                        <td><a href="/#session.rootDir#/users/viewuser.cfm?ADUser=#trim(Manager)#">#AllGroups.SCFAD.getAccountNameByDN(managedBy)#</a></td>
                        <td>#AllGroups.ADGroupTypes[groupType]#</td>
                        <td>#ArrayLen(AllGroups.parseUserDNString(member))#</td>
                    </tr>
                </cfloop>
            </tbody>
        </table>
    </cfform>
</cffunction>
